package com.ocr;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import com.ocr.*;
import com.adapter.HistoryAdapter;
import com.adapter.LanguageAdapter;
import com.entity.HistoryItem;
import com.entity.LanguageContext;
import com.util.OCRCostant;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;

public class HistoryActivity extends Activity {
	private ListView listViewHistory;
	public static  HistoryAdapter historyAdapter;
	public static List<HistoryItem> listHistory;
	public static LinearLayout layoutNoHistory;
	private ImageButton btnDelete;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.history_activity);
		listViewHistory=(ListView) findViewById(R.id.list_history);
		btnDelete=(ImageButton) findViewById(R.id.btn_delelte);
		layoutNoHistory=(LinearLayout) findViewById(R.id.nohistoty_layout);
	
		listHistory=MainActivity.HISTORY_DAO.loadAll();
		if(listHistory.size()==0||listHistory==null)
		{
			layoutNoHistory.setVisibility(View.VISIBLE);
		}
		Collections.sort(listHistory);
		historyAdapter=new  HistoryAdapter(getApplicationContext(), R.layout.item_history,listHistory);
		listViewHistory.setAdapter(historyAdapter);
		listViewHistory.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
					long arg3) {
				// TODO Auto-generated method stub
				Intent intent=new Intent(HistoryActivity.this,ResultActivity.class);
				String content=listHistory.get(pos).getOCRResult();
				System.out.println("----click item:"+content);
				intent.putExtra(OCRCostant.ITENT_HISTROY_TO_RESULT,content);
				startActivity(intent);
			}
		});
		btnDelete.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent=new Intent(HistoryActivity.this,SelectTimeDelActivity.class);
				startActivity(intent);
			}
		});
	}
	
}
